package org.jsola.hr.common;

import lombok.NonNull;

/**
 * redis缓存key都定义在该类
 *
 * @author zhr
 */
public class CacheKeyKit {

    private static final String PRE_FIX = "jsola:hr";

    private static final String EMP_PRE = PRE_FIX + ":emp";

    private static final String OFFER_PRE = EMP_PRE + ":offer";

    private static final String TICKET_PRE = EMP_PRE + ":ticket";

    private static final String ATTEND_PUNCH_CHECKINFO = EMP_PRE + ":attend:punch:checkinfo";

    private static final String ATTEND_PUNCH_RECORD = EMP_PRE + ":attend:punch:record";

    private static final String APP_AUTH_TOKEN = PRE_FIX + ":appAuthToken";

    private static final String THROUGH_TRAIN = PRE_FIX + ":train";

    private static final String WEIXIN = PRE_FIX + ":weiXin";

    /**
     * 缓存offer的key
     *
     * @param offerInfoId offerInfoId
     * @return key
     */
    public static String getOfferCacheKey(@NonNull String offerInfoId) {
        return OFFER_PRE + ":" + offerInfoId;
    }

    /**
     * 缓存员工ticket的key
     *
     * @param ticket
     * @return key
     */
    public static String getTicketCacheKey(@NonNull String ticket) {
        return TICKET_PRE + ":" + ticket;
    }

    /**
     * 获取考勤打卡序号
     *
     * @param punchNumber
     * @return
     */
    public static String getAttendPunchCheckInfo(String punchNumber) {
        return ATTEND_PUNCH_CHECKINFO + ":" + punchNumber;
    }

    /**
     * 身份证实名认证
     *
     * @param idcard 身份证号
     * @return 身份证号key
     */
    public static String getIdCardVerified(String empId, String idcard) {
        return PRE_FIX + ":verified:idcard:" + idcard + ":empId:" + empId;
    }

    /**
     * 身份证是否能实名认证,控制频率
     *
     * @param idcard 身份证号
     * @return 身份证号是否能认证key
     */
    public static String getIdCardCanVerified(String empId, String idcard) {
        return PRE_FIX + ":verified:can:idcard:" + idcard + ":empId:" + empId;
    }

    /**
     * 身份证实名认证锁定
     *
     * @param idcard 身份证号
     * @return 身份证号是否能认证key
     */
    public static String getIdCardLockVerified(String empId, String idcard) {
        return PRE_FIX + ":verified:lock:idcard:" + idcard + ":empId:" + empId;
    }

    /**
     * 当前用户社保账号
     *
     * @param userId 身份证号
     * @return 身份证号是否能认证key
     */
    public static String getSocAccount(String userId, String areaId) {
        return PRE_FIX + ":account:soc:socCacheUser:" + userId + "areaId" + areaId;
    }

    /**
     * 当前用户医保账号
     *
     * @param userId 身份证号
     * @return 身份证号是否能认证key
     */
    public static String getMeAccount(String userId, String areaId) {
        return PRE_FIX + ":account:me:socCacheUser:" + userId + "areaId" + areaId;
    }

    /**
     * 当前用户公积金账号
     *
     * @param userId 身份证号
     * @return 身份证号是否能认证key
     */
    public static String getPfAccount(String userId, String areaId) {
        return PRE_FIX + ":account:pf:socCacheUser:" + userId + "areaId" + areaId;
    }

    public static String getSmallProgram() {
        return PRE_FIX + ":account:smallProgram";
    }

    /**
     * 根据公司id获取小程序二维码
     *
     * @param companyId 用工单位id
     * @return 公司小程序二维码key
     */
    public static String getQRCode(String companyId) {
        return PRE_FIX + ":QRCode:companyId:" + companyId;
    }

    /**
     * 根据公司id和用户Id获取小程序二维码
     *
     * @param companyId 用工单位id
     * @return 公司小程序二维码key
     */
    public static String getQRCodeAndUserId(String companyId, String userId) {
        return PRE_FIX + ":QRCode:companyId:" + companyId + ":" + userId;
    }

    /**
     * 根据公司id获取管理端小程序二维码
     *
     * @param companyId 用工单位id
     * @param type      类型；1：预登记 2：待入职
     * @param userId    userId
     * @return 公司小程序二维码key
     */
    public static String getManageQRCode(String companyId, Integer type, String userId) {
        return PRE_FIX + ":manage:" + companyId + ":" + type + ":" + userId;
    }

    /**
     * 根据公司id获取员工标签库
     *
     * @param siteId    租户id
     * @param companyId 用工单位id
     * @return 员工标签
     */
    public static String getTag(String siteId, String companyId) {
        return PRE_FIX + ":tag:" + siteId + ":" + companyId;
    }

    /**
     * 获取动态码
     *
     * @param code 动态码
     * @return 动态码
     */
    public static String getDynamicCode(String code) {
        return PRE_FIX + ":dynamicCode:" + code;
    }

    /**
     * 获取补缺卡key
     *
     * @param day 日期
     * @return 补缺卡key
     */
    public static String getAttendPunchRecordCacheKey(String day) {
        return ATTEND_PUNCH_RECORD + ":" + day;
    }

    /**
     * 获取租户的appAuthToken的Key（批量转账使用）
     *
     * @param pid pid
     * @return appAuthToken的Key
     */
    public static String getSiteAppAuthTokenCacheKey(String pid) {
        return APP_AUTH_TOKEN + ":" + pid;
    }

    /**
     * 获取一键发薪审批的key
     *
     * @param batchId 批次id
     * @param flowId  审批模板id
     * @param siteId  租户id
     * @return 发薪审批的key
     */
    public static String getOneKeyPayApproKey(String batchId, String flowId, String siteId) {
        return PRE_FIX + ":" + "siteId" + ":" + siteId + ":" + "batchId" + ":" + batchId + ":" + "flowId" + ":" + flowId;
    }

    /**
     * 政企直通车 Access_token
     *
     * @param appId appId
     * @return Access_token
     */
    public static String getAccessTokenByAppId(String appId) {
        return THROUGH_TRAIN + ":" + appId;
    }

    /**
     * 获取花名册导入的key
     *
     * @param companyId 用工单位id
     * @return key
     */
    public static String getEmpInfoImportKey(String companyId) {
        return EMP_PRE + ":import:" + companyId;
    }

    /**
     * 公司批量签署合同key
     *
     * @param companyId
     * @return
     */
    public static String getEnterpriseSignKey(String companyId) {
        return PRE_FIX + ":enterpriseSign:" + companyId;
    }

    /**
     * 租户批量下发入职模板key
     *
     * @param siteId 租户Id
     * @return 租户批量下发入职模板key
     */
    public static String getIssueTemplate(String siteId) {
        return PRE_FIX + ":issueTemplate:" + siteId;
    }

    /**
     * 公司批量发起合同
     *
     * @param subjectId
     * @return
     */
    public static String getPublishTemplateSignKey(String subjectId) {
        return PRE_FIX + ":publishTemplateSign:" + subjectId;
    }

    public static String getGysHeader(String moduleCode, String createUserId) {
        return PRE_FIX + ":gysHeader:" + moduleCode + ":" + createUserId;
    }

    /**
     * 社保总览保存表头
     *
     * @param siteId 站点
     * @param userId userId
     * @return key
     */
    public static String getSocOverviewHeadKey(String siteId, String userId) {
        return PRE_FIX + ":SocOverviewHead:" + siteId + ":" + userId;
    }

    public static String getAccessToken(String appId) {
        return PRE_FIX + ":accessToken:" + appId;
    }

    public static String getRegisterSend() {
        return PRE_FIX + ":register";
    }

    /**
     * 获取订阅回复信息
     * @param siteId 站点Id
     * @return 订阅回复信息
     */
    public static String getSubscribeContent(String siteId) {
        return WEIXIN + ":subscribe:content:" + siteId;
    }
}
